
//  tTask.c
//
//  Created on: 2019年7月16日
//  Author: cludu
//



#include "tTask.h"

#define TRUE    0x01
#define FALSE    0x00

#define TASK_ALL    0xff


uint8_t tTaskMain;        //系统主任务
uint8_t tTaskSub[8];     //系统子任务





Task_TypeDef Tasklist[8] =
{   //任务列表 TASK0优先级最高
    MaskTask0,
    MaskTask1,
    MaskTask2,
    MaskTask3,
    MaskTask4,
    MaskTask5,
    MaskTask6,
    MaskTask7
};


const uint8_t TaskPrioTable[256] =
{
    0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
};



void Set_Task(uint8_t MainTask,uint8_t SubTask)
{
    uint16_t mt, st;
    mt = 1 << MainTask;
    st = 1 << SubTask;
    tTaskMain |= mt;
    tTaskSub[MainTask] |= st;
}

void Clr_Task(uint8_t MainTask,uint8_t SubTask)
{
    uint8_t ss;
    if(SubTask == TASK_ALL)
    {
        tTaskSub[MainTask] = 0;
    }
    else
    {
        ss = 1 << SubTask;
        tTaskSub[MainTask] &= ~ss;
    }
}

uint8_t clear_task(uint8_t Prio , uint8_t PrioMask)
{
    tTaskSub[Prio] &= ~(1 << PrioMask);
    if(tTaskSub[Prio] == 0)
    {
        tTaskMain &= ~(1 << Prio);
        return TRUE;
    }
    return FALSE;
}




